import $http from "@/services";
export default {
    state: {
        salaryLists: [],
        salaryTotal: 0,
        salaryDetail: null,
        salarySearch: {
            page: 1,
            size: 5,
            queryData: {}
        }
    },
    // 赋值
    reducers: {
        setSalaryLists(state, { payload }) {
            return { ...state, salaryLists: payload }
        },
        setSalaryTotal(state, { payload }) {
            return { ...state, salaryTotal: payload }

        },
        setSalaryDetail(state, { payload }) {
            return { ...state, salaryDetail: payload }
        },
        setSalarySearch(state, { payload }) {
            return { ...state, salarySearch: { ...state.salarySearch, ...payload } };
        }
    },
    effects: {
        // 初始化数据，获取数据
        *initSalaryContent({ payload }, { put, call, select }) {
            // 重新处理请求关系
            yield put({
                type: "setSalarySearch",
                payload
            })
            const { salarySearch } = yield select(state => state.salary);
            //请求数据
            const { data, msg } = yield call($http.getSalaryList, salarySearch);
            console.log(data)
            yield put({
                type: "setSalaryLists",
                payload: data.list
            })
            yield put({
                type: "setSalaryTotal",
                payload: data.total
            })

        },
        // 重新获取职级详情
        *getDetailSalary({ payload }, { put, call }) {
            const { data } = yield call($http.getSalaryDetail, payload);
            console.log(data)
            if (data) {
                yield put({
                    type: "setSalaryDetail",
                    payload: data
                })
                yield put({
                    type: "common/setIsShowDetail",
                    payload: true
                });
            }

        }
    }
}